/**
 * Created by Tuffy on 16/1/18.
 */
'use strict';

angular.module('starter.controllers')

.controller('FormController', ['$scope', '$state', function($scope, $state) {


    //$scope.form = {
    //    modal:$scope.formModal,
    //    title:'',
    //    type:'MultiSelect',
    //    dict:[],
    //    otherValue:'',
    //    onOk:function(){
    //
    //    },
    //    onCancel:function(){
    //
    //    }
    //};
    $scope.onCancel = function(){
        $scope.form.onCancel && $scope.form.onCancel();
        $scope.form.modal.hide();
    };
    $scope.onOk = function(){
        var keys = [],
            values = [];
        angular.forEach($scope.form.dict,function(item,index){
            if(item.checked){
                keys.push(item.id);
                values.push(item.name);
            }
        });
        $scope.form.onOk && $scope.form.onOk(keys,values);
        $scope.form.modal.hide();
    };
}]);